# set minimum cmake version
## 低于3.10, VSCode不支持SSH调试
cmake_minimum_required(VERSION 3.16)

project(PSRedis LANGUAGES C CXX)

# 打印出更详细的编译内容
# set(CMAKE_VERBOSE_MAKEFILE ON)

# C/C++ Language Standard
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 构建环境的操作系统
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    message(STATUS "Configuring on/for Linux")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
    message(STATUS "Configuring on/for macOS")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
    message(STATUS "Configuring on/for Windows")
elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
    message(STATUS "Configuring on/for IBM AIX")
else()
    message(STATUS "Configuring on/for ${CMAKE_SYSTEM_NAME}")
endif()

# 32bits, 64bits
if(USE_32BITS STREQUAL "True")
    message(STATUS "using 32bits")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
else()
   message(STATUS "using 64bits")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
endif()

# 检测处理器体系结构
message(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR=${CMAKE_HOST_SYSTEM_PROCESSOR}")
message(STATUS "CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i386")
	message(STATUS "i386 architecture detected")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i686")
	message(STATUS "i686 architecture detected")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
	message(STATUS "x86_64 architecture detected")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64")
	message(STATUS "x64 architecture detected")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") # arm
	message(STATUS "aarch64 architecture detected")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "mips64")
	message(STATUS "mips64 architecture detected")
else()
	message(STATUS "host processor architecture is unknown")
endif()

# Debug, Release
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 ")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
else()
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 ")
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
endif()

message(STATUS "CMAKE_C_FLAGS ${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")

# 设置工程路径
SET(ROOT_DIR ${PROJECT_SOURCE_DIR})
message(STATUS "ROOT_DIR- ${ROOT_DIR}")

# 设置依赖库目录
set(LIB_DIR "${ROOT_DIR}/lib")
message(STATUS "LIB_DIR 依赖库目录 - ${LIB_DIR}")

# 设计头文件目录
set(INCLUDE_DIR "${ROOT_DIR}/include")
message(STATUS "INCLUDE_DIR 依赖库目录 - ${INCLUDE_DIR}")

SET(LIBRARY_OUTPUT_PATH ${ROOT_DIR}/lib)
message(STATUS "LIBRARY_OUTPUT_PATH - ${LIBRARY_OUTPUT_PATH}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ROOT_DIR}/run")
message(STATUS "CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")

add_subdirectory(01_hiredis)
add_subdirectory(02_ps)